#ifndef XRDDMLOG_H
#define XRDDMLOG_H

#define XrdDMLogInfo(...) gLog->Info(__VA_ARGS__)
#define XrdDMLogOk(...) gLog->Ok(__VA_ARGS__)
#define XrdDMLogWarning(...) gLog->Warning(__VA_ARGS__)
#define XrdDMLogError(...) gLog->Error(__VA_ARGS__)
#define XrdDMLogFatal(...) gLog->Fatal(__VA_ARGS__)
#define XrdDMLogDebugSilent(...) gLog->Debug(1,__VA_ARGS__)
#define XrdDMLogDebugMedium(...) gLog->Debug(2,__VA_ARGS__)
#define XrdDMLogDebugFull(...) gLog->Debug(3,__VA_ARGS__)

typedef enum { kMsgOk, kMsgInfo, kMsgWarning, kMsgError, kMsgFatal, kMsgDebug }
  MsgType_t;

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <stdarg.h>
#include <cstdlib>
#include <time.h>
using namespace std;

class XrdDMLog {

  public:
    // Methods
    XrdDMLog(int debug = 0);
	~XrdDMLog();
	
	static void Init(bool debug = false);
    static void Delete();
    void        SetDebug(int debug);
    void        SetBanner(const char *msg) { fBanner = msg; };
    void        PrintBanner();
    int         GetDebug() { return fDebug; };
    bool        SetFile(const char *fn);
    void        SetStdErr();
    void        Debug(int debug , const char *fmt, ...);
    void        Info(const char *fmt, ...);
    void        Ok(const char *fmt, ...);
    void        Warning(const char *fmt, ...);
    void        Error(const char *fmt, ...);
    void        Fatal(const char *fmt, ...);

  private:

    void CheckRotateAndFormat(MsgType_t type, const char *fmt, va_list args);
    void Format(MsgType_t type, const char *fmt, va_list args);
    int CheckRotate();

    // Constants
    FILE *kStdErr;

    // Variables
    FILE      *fLogFile;
    time_t     fDatime;
    time_t     fLastRotated;
    string     fLogFileName;
    bool       fRotateable;
    string     fBanner;
    int        fDebug;

};

extern XrdDMLog *gLog;

#endif // XRDDMLOG_H
